#!/bin/sh

#@echo off
#rem Param 1: System User
#rem Parma 2: OMS Database
#rem Param 3: OMS User

system_user=$1
oms_database=$2 
oms_user=$3

if [ -z "$system_user" ]; then
    error="err" 
fi

if [ -z "$oms_database" ]; then 
    error="err" 
fi

if [ -z "$oms_user" ]; then
    error="err" 
fi

if [ -n "$error" ]; then
    echo 'Missing parameter!'
    echo 'Syntax:'
    echo 'omssetup [system user] [new oms database] [new oms user]'
else
	echo ""
	echo "DROP DATABASE $oms_database
	dropdb -U $system_user -i -e $oms_database
	echo ""
	echo "DROP USER $oms_user"
	dropuser -U $system_user -i -e $oms_user
	echo ""
	echo "CREATE USER $oms_user"
	createuser -U $system_user -e -A -d -P $oms_user
	echo ""
	echo "CREATE DATABASE oms_database"
	createdb -U $oms_user -e oms_database
	echo ""
	echo "PSQL"
	psql -d oms_database -U $oms_user -f setup/oms_install.sql
fi
